home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_094 / clickupfront / click-handler.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  144 lines

  1. /*
  2.  *  Click-Handler.c     Input Handler for ClickUpFront, which brings a
  3.  *                      window to the front when you double-click in it.
  4.  *
  5.  *              Copyright (c) 1987 by Davide P. Cervone
  6.  *  You may use this code provided this copyright notice is left intact.
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <devices/inputevent.h>
  11. #include <intuition/intuitionbase.h>
  12.  
  13. static char *version = "Click-Handler v1.0 (July 1987)";
  14. static char *author  = "Copyright (c) 1987 by Davide P. Cervone";
  15.  
  16. extern struct Layer *WhichLayer();
  17. extern void myHandlerStub();
  18.  
  19. #define WINDOW(layer)   ((struct Window *)((layer)->Window))
  20. #define SCREENTOP\
  21.    (theScreen->TopEdge << ((theScreen->ViewPort.Modes & LACE)? 0: 1))
  22. #define ie_Secs         ie_TimeStamp.tv_secs
  23. #define ie_Mics         ie_TimeStamp.tv_micro
  24.  
  25. long LastSecs = 0;      /* seconds field from last mouse click */
  26. long LastMics = 0;      /* micros  field from last mouse click */
  27. long StayMask;          /* qualifier keys that allow you to double click */
  28.                         /* a window without bringing it to the front */
  29.  
  30.  
  31. struct IntuitionBase *IntuitionBase = NULL;
  32. struct LayersBase    *LayersBase    = NULL;
  33. struct SysBase       *SysBase       = NULL;
  34.  
  35. /*
  36.  *  Setup()
  37.  *
  38.  *  ClickUpFront calls LoadSeg() to get this handler into memory.  The segment
  39.  *  that it gets points to this routine.  ClickUpFront calls Setup() and 
  40.  *  passes the IntuitionBase, LayersBase and SysBase pointers that it
  41.  *  has initialized (with OpenLibrary()).  Setup returns a pointer to
  42.  *  the actual input handler, which ClickUpFront installs.
  43.  */
  44.  
  45. long Setup(Ibase,Lbase,Sbase,flags)
  46. struct IntuitionBase *Ibase;
  47. struct LayersBase *Lbase;
  48. struct SysBase *Sbase;
  49. long flags;
  50. {
  51.    IntuitionBase = Ibase;
  52.    LayersBase = Lbase;
  53.    SysBase = Sbase;
  54.    StayMask = flags;
  55.    return((long) &myHandlerStub);
  56. }
  57.  
  58.  
  59. /*
  60.  *  myHandler()
  61.  *
  62.  *  This is the input handler.  For each event in the event list:
  63.  *  If it is a raw mouse event:
  64.  *    if it is a left button click, then
  65.  *      if the mouse has not moved since the last click and the user is
  66.  *          not holding down the keys that allow windows to stay put, then
  67.  *        if the time since the last click was less than the double click time,
  68.  *          Find the screen where the mouse is pointing.
  69.  *          Find the top window on the that screen.
  70.  *          If there is one, then
  71.  *            find the Layer in which the click occured.
  72.  *            if that Layer's window is not already at the top,
  73.  *              bring it to the top.
  74.  *      Set the time since the last click to the current time.
  75.  *    Otherwise, it was not a left button click, so
  76.  *      ignore lift button up messages, but set the times to zero (a long time
  77.  *         ago) if the mouse moved or the right button was clicked.
  78.  *  If the event was a keyboard event, then set the times to zero.
  79.  *  Ignore all other event types (timer, disk).
  80.  *
  81.  *  Finally, return the event list so that Intuition can do its thing.
  82.  *
  83.  */
  84.  
  85. struct InputEvent *myHandler(EventList,data)
  86. struct InputEvent *EventList;
  87. APTR data;
  88. {
  89.    register struct InputEvent *theEvent = EventList;
  90.    register struct Layer  *theLayer, *topLayer;
  91.    register struct Screen *theScreen;
  92.  
  93.    Forbid();
  94.    while(theEvent)
  95.    {
  96.       switch(theEvent->ie_Class)
  97.       {
  98.          case IECLASS_RAWMOUSE:
  99.             if (theEvent->ie_Code == SELECTDOWN)
  100.             {
  101.                if (theEvent->ie_X == 0 && theEvent->ie_Y == 0 &&
  102.                   (theEvent->ie_Qualifier & StayMask) == 0)
  103.                {
  104.                   if (DoubleClick(LastSecs,LastMics,
  105.                       theEvent->ie_Secs,theEvent->ie_Mics))
  106.                   {
  107.                      theScreen = IntuitionBase->FirstScreen;
  108.                      while (theScreen && IntuitionBase->MouseY < SCREENTOP)
  109.                         theScreen = theScreen->NextScreen;
  110.                      if (theScreen == NULL)
  111.                         theScreen = IntuitionBase->ActiveScreen;
  112.                      if (theScreen != IntuitionBase->FirstScreen)
  113.                         ScreenToFront(theScreen);
  114.  
  115.                      topLayer = theScreen->LayerInfo.top_layer;
  116.                      while (topLayer && WINDOW(topLayer) == NULL)
  117.                         topLayer = topLayer->back;
  118.                      if (topLayer)
  119.                      {
  120.                         theLayer = WhichLayer(&(theScreen->LayerInfo),
  121.                                    theScreen->MouseX,theScreen->MouseY);
  122.                         if (theLayer && WINDOW(theLayer) != WINDOW(topLayer))
  123.                            WindowToFront(WINDOW(theLayer));
  124.                      }
  125.                   }
  126.                }
  127.                LastSecs = theEvent->ie_Secs;
  128.                LastMics = theEvent->ie_Mics;
  129.             } else {
  130.                if (theEvent->ie_Code != SELECTUP)
  131.                   LastSecs = LastMics = 0;
  132.             }
  133.             break;
  134.  
  135.          case IECLASS_RAWKEY:
  136.             LastSecs = LastMics = 0;
  137.             break;
  138.       }
  139.       theEvent = theEvent->ie_NextEvent;
  140.    }
  141.    Permit();
  142.    return(EventList);
  143. }
  144.